package com.zh.kotlin_mvvm.ui;

import androidx.annotation.Nullable;

import android.os.Bundle;
import com.zh.common.base.BaseActivity;
import com.zh.kotlin_mvvm.camera2.Camera2Proxy;
import com.zh.kotlin_mvvm.camera2.Camera2SurfaceView;
import com.zh.kotlin_mvvm.databinding.ActivityCamera2Binding;

public class Camera2Activity extends BaseActivity<ActivityCamera2Binding> {

    private Camera2Proxy mCameraProxy;
    private Camera2SurfaceView mCameraView;

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {

        mCameraView = getViewBinding().surfaceView;
        mCameraProxy = mCameraView.getCameraProxy();

        mCameraView.post(() -> {
            mCameraProxy.startCamera();
        });

        getViewBinding().change.setOnClickListener(v -> {
            mCameraProxy.switchCamera();
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mCameraProxy.stopPreview();
    }
}